package com.chzu.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chzu.mapper.QuestionChoseMapper;
import com.chzu.pojo.QuestionChose;
import com.chzu.result.JsonResult;
import com.chzu.result.PageResult;
import com.chzu.result.QueryInfo;
import com.chzu.service.QuestionChoseService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author lz
 * @Version 1.0
 * @Company 滁州大健康与养老产业研究院
 * @ClassName QuestionChoseServiceImpl
 * @Description TODO
 * @Date 2022/02/21 19:19
 */
@Service
public class QuestionChoseServiceImpl extends ServiceImpl<QuestionChoseMapper, QuestionChose> implements QuestionChoseService {

    @Resource
    private QuestionChoseMapper questionChoseMapper;

    /**
     * 分页查询所有选项信息
     * @param queryInfo 模糊查询
     * @return
     */
    @Override
    public JsonResult<Object> getAllQuestionChose(QueryInfo queryInfo) {
        PageHelper.startPage(queryInfo.getPageNumber(), queryInfo.getPageSize());
        Page<QuestionChose> page = questionChoseMapper.getAllQuestionChose(queryInfo.getQueryString());
        long total = page.getTotal();
        List<QuestionChose> result = page.getResult();
        return PageResult.pageResult(result, total);
    }

    /**
     * 按照题目id以及选项修改内容
     * @param questionChose 选项信息
     */
    @Override
    public int putQuestionChose(QuestionChose questionChose) {
        questionChose.setChoseId(Character.toUpperCase(questionChose.getChoseId()));
        return questionChoseMapper.putQuestionChose(questionChose);
    }
}
